package com.jobs.repositories;

import com.jobs.pojo.Customer;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author 王博
 */
public interface CustomerZiDingYiRepository extends PagingAndSortingRepository<Customer, Long> {

    @Query("from Customer where name = ?1")
    Customer findByName(String name);

    @Query("from Customer where name = :name")
    Customer findByName2(@Param("name") String name);



    @Transactional
    @Modifying
    @Query("update Customer c set c.name=:name where c.id=:id")
    int updateNameById(@Param("name") String name, @Param("id") Long id);

    @Transactional
    @Modifying
    @Query("delete from Customer c where c.id=:id")
    int delById(@Param("id")Long id);


    @Query("select c from Customer c where c.name = :name")
    Page<Customer> page(@Param("name")String name, Pageable pageable);
}
